package com.ruoyi.syrw.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.syrw.domain.vo.BaReportGroupDetailVo;
import com.ruoyi.syrw.domain.bo.BaReportGroupDetailBo;
import com.ruoyi.syrw.service.IBaReportGroupDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试验任务预选分组详细
 *
 * @author zyb
 * @date 2024-06-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/syrw/baReportGroupDetail")
public class BaReportGroupDetailController extends BaseController {

    private final IBaReportGroupDetailService iBaReportGroupDetailService;

    /**
     * 查询试验任务预选分组详细列表
     */
    @SaCheckLogin
//    @GetMapping("/list")
    public TableDataInfo<BaReportGroupDetailVo> list(BaReportGroupDetailBo bo, PageQuery pageQuery) {
        return iBaReportGroupDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出试验任务预选分组详细列表
     */
    @SaCheckLogin
    @Log(title = "试验任务预选分组详细", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
    public void export(BaReportGroupDetailBo bo, HttpServletResponse response) {
        List<BaReportGroupDetailVo> list = iBaReportGroupDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "试验任务预选分组详细", BaReportGroupDetailVo.class, response);
    }

    /**
     * 获取试验任务预选分组详细详细信息
     *
     * @param bsId 主键
     */
    @SaCheckLogin
//    @GetMapping("/{bsId}")
    public R<BaReportGroupDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long bsId) {
        return R.ok(iBaReportGroupDetailService.queryById(bsId));
    }

    /**
     * 新增试验任务预选分组详细
     */
    @SaCheckLogin
    @Log(title = "试验任务预选分组详细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
//    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BaReportGroupDetailBo bo) {
        return toAjax(iBaReportGroupDetailService.insertByBo(bo));
    }

    /**
     * 修改试验任务预选分组详细
     */
    @SaCheckLogin
    @Log(title = "试验任务预选分组详细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
//    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BaReportGroupDetailBo bo) {
        return toAjax(iBaReportGroupDetailService.updateByBo(bo));
    }

    /**
     * 删除试验任务预选分组详细
     *
     * @param bsIds 主键串
     */
    @SaCheckLogin
    @Log(title = "试验任务预选分组详细", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{bsIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] bsIds) {
        return toAjax(iBaReportGroupDetailService.deleteWithValidByIds(Arrays.asList(bsIds), true));
    }
}
